<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="/WEB-INF/c.tld"%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="admin/Hui/lib/html5.js"></script>
<script type="text/javascript" src="admin/Hui/lib/respond.min.js"></script>
<script type="text/javascript" src="admin/Hui/lib/PIE_IE678.js"></script>
<![endif]-->
<link href="admin/Hui/css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="admin/Hui/css/H-ui.admin.css" rel="stylesheet"
	type="text/css" />
<link href="admin/Hui/lib/font-awesome/font-awesome.min.css"
	rel="stylesheet" type="text/css" />
<!--[if IE 7]>
<link href="admin/Hui/lib/font-awesome/font-awesome-ie7.min.css" rel="stylesheet" type="text/css" />
<![endif]-->
<link href="admin/Hui/lib/iconfont/iconfont.css" rel="stylesheet"
	type="text/css" />
<!--[if IE 6]>
<script type="text/javascript" src="admin/Hui/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<script type="text/javascript" src="admin/Hui/js/jquery-1.7.2.js"></script>
<title>报障管理</title>
<style>
.navul ul li {
	float: left;
	padding-left: 5px;
	text-align: center;
}

.navul {
	width: 500px;
	height: 32px;
	margin: auto;
}
</style>
<script>
$(function(){
	$("[name='deleteBtn']").on("click",function del() {
		var deleteBtn = $(this);
		var deleteId = $(this).parent().parent().find("[name='repairIdParent']").find("[name='check_id']").val();
		if (confirm("真的要删除该条记录吗?")) {
		$.post("repair!deleteWaitingRepair.action", {
			repair_id : deleteId
		} , function(data, status) {
			if (data == 1) 
			{
				deleteBtn.parent().parent().remove();
				var totalCount = parseInt($("#totalCount").html());
				var stateTotalCount = parseInt($("#stateTotalCount").html());
				totalCount --;
				stateTotalCount --;
				$("#totalCount").html(totalCount);
				$("#stateTotalCount").html(stateTotalCount)
				
			}else
			{
				alert("删除失败");
			}
		});
		}
		
	});
});

	function moredelete() {
		var chk_value = [];
		$('input[name="check_id"]:checked').each(function() {
			chk_value.push($(this).val());
		});
		if (chk_value.length == 0) {
			alert("未选择");
		} else {
			var mes = confirm("是否删除？");
			if (mes == true) {
				$("#formdelete").submit();
			}
		}
	}
</script>
</head>
<body>
	<nav class="breadcrumb">
		<span><img src="admin/images/leftico01.png" /></span> 报障管理 <span
			class="c-gray en">&gt;</span> 等待处理 <a
			class="btn btn-success radius r mr-20"
			style="line-height: 1.6em; margin-top: 3px"
			href="javascript:location.replace(location.href);" title="刷新"><i
			class="icon-refresh"></i></a>
	</nav>
	<div class="pd-20">
		<div class="text-c">
			报障时间范围： <input type="text"
				onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}'})"
				id="datemin" name="datemin" class="input-text Wdate"
				style="width: 120px;"> - <input type="text"
				onfocus="WdatePicker({minDate:'#F{$dp.$D(\'datemin\')}',maxDate:'%y-%M-%d'})"
				id="datemax" name="datemax" class="input-text Wdate"
				style="width: 120px;"> <input type="text" class="input-text"
				style="width: 250px" placeholder="输入报障人或宿舍号或上门时间" id="searchname"
				name="searchname">
			<button type="button" class="btn btn-success" id="tosubmit">
				<i class="icon-search"></i> 搜报障
			</button>
		</div>
		<div class="cl pd-5 bg-1 bk-gray mt-20">
			<span class="l"><a id="moredelete"
				class="btn btn-danger radius" onclick="moredelete()"><i
					class="icon-trash"></i> 批量删除</a> <a href="repair!prepareInsert.action"
				class="btn btn-primary radius"> <i class="icon-plus"></i> 添加报障
			</a></span> <span class="r"> 总报障数：<strong id="totalCount">${totalCount}</strong>
			</span><span class="r"> 等待处理数：<strong id="stateTotalCount">${stateTotalCount}</strong>&nbsp;&nbsp;
			</span>
		</div>
		<form action="repair!moredelete.action" method="post" id="formdelete">
			<table
				class="table table-border table-bordered table-hover table-bg table-sort">
				<thead>

					<tr class="text-c">
						<th width="25"><input type="checkbox" name="" value=""></th>
						<th width="80">报障ID</th>
						<th width="100">报障人</th>
						<th width="80">电话</th>
						<th width=300">描述</th>
						<th width="5">宿舍</th>
						<th width="80">上门时间</th>
						<th width="50">报障状态</th>
						<th width="130">报障时间</th>
						<th width="30">受理</th>
						<th width="30">删除</th>
					</tr>

				</thead>
				<tbody>
					<s:iterator value="repairList">
						<tr class="text-c">
							<td name="repairIdParent"><input type="checkbox" value="${repair_id }"
								name="check_id"></td>
							<td>${repair_id }</td>

							<td><u style="cursor: pointer" class="text-primary"
								onclick="user_show('10001','400','','${user_name }','user!show.action?user_id=${user_id }')">${user_name }</u></td>
							<td>${user_phone }</td>
							<td>${repair_content }</td>
							<td>${repair_addr }</td>
							<td>${go_time }</td>
							<td name="repair_state">${repair_state }</td>
							<td>${repair_submit_time }</td>
							
							<td class="f-14 user-manage"><a title="受理"
								href="repair!acceptRepair.action?repair_id=${repair_id }" class="ml-5"
								style="text-decoration: none" name="acceptRepairA"> <i class="icon-save"></i></a> 
							</td>
							<td>	
								<a title="删除" name="deleteBtn" 
								onclick="return del()" class="ml-5 deleteBtn"
								style="text-decoration: none"> <i class="icon-trash"></i>
							</a></td>
						</tr>
					</s:iterator>
				</tbody>
			</table>
		</form>

	</div>
	
	<script>
	$("#tosubmit").on("click", function(){
		$.post("repair!search.action", {
			searchname: $("#searchname").val(),
			datemin: $("#datemin").val(),
			datemax: $("#datemax").val(),
			flag: "等待处理"
		}, function(data){
			var json = JSON.parse(data);
			if (json.page.currentPage != 1) {
				$("#first").show();
			} else {
				$("#first").hide();
				$("#next").attr("href",
						"javascript:showPage(2)");
				$("#last").show();
			}
			if (json.page.hasPrePage) {
				$("#prev").show();
				$("#prev").attr(
						"href",
						"javascript:showPage("
								+ (json.page.currentPage - 1)
								+ ")");
			} else {
				$("#prev").hide();
			}
			if (json.page.hasNextPage) {
				$("#next").show();
				$("#next").attr(
						"href",
						"javascript:showPage("
								+ (json.page.currentPage + 1)
								+ ")");
			} else {
				$("#next").hide();
				$("#last").hide();
			}
			if (json.page.currentPage < json.page.totalPage) {
				$("#last").show();
			} else {
				$("#last").hide();
			}
			$("#current").html("第" + json.page.currentPage + "页");
			$("#total").html("共" + json.page.totalPage + "页");
			$("tbody").empty();
			console.log(json.list);
			$.each(json.list,function(n, obj) {
				var strhtml = "<tr class='text-c'>";
				strhtml += "<td><input type='checkbox' name='chk_id' value='" + obj.repair_id + "' /></td>";
				strhtml += "<td>" + obj.repair_id
						+ "</td>";
				strhtml += "<td><u style='cursor: pointer' class='text-primary'"
						+ " onclick='user_show('10001','400','','" + obj.user_name + "','user!show.action?user_id=" + obj.user_id + "')'>"
						+ obj.user_name + "</u></td>"
				strhtml += "<td>"
						+ (obj.repair_content==null?'':obj.repair_content)
						+ "</td>";
				strhtml += "<td>"
						+ (obj.repair_addr==null?'':obj.repair_addr)
						+ "</td>";
				strhtml += "<td>"
						+ (obj.repair_state==null?'':obj.repair_state)
						+ "</td>";
				strhtml += "<td>"
						+ (obj.repair_submit_time==null?'':obj.repair_submit_time)
						+ "</td>";
				strhtml += "<td>"
						+ (obj.repair_person_name==null?'':obj.repair_person_name)
						+ "</td>";
				strhtml += "<td><a title='删除' class='ml-5' name='deleteBtn'" 
						+ "style='text-decoration: none'> <i class='icon-trash'></i></a></td>"
				strhtml += "<td class='f-14 user-manage'>"
						+ "<a title='等待维修' href='repair!waitingRepair.action?repair_id=" + obj.repair_id + "' class='ml-5'"
						+ "style='text-decoration: none' name='waitingRepairA'> <i class='icon-edit'></i></a><span>&nbsp;&nbsp;</span>"
						+ "<a title='正在处理' href='repair!repairing.action?repair_id=" + obj.repair_id + "' class='ml-5'"
						+ "style='text-decoration: none' name='repairingA'> <i class='icon-print'></i></a><span>&nbsp;&nbsp;</span>"
						+ "<a title='维修成功' href='repair!successRepair.action?repair_id=" + obj.repair_id + "' class='ml-5'"
						+ "style='text-decoration: none' name='successRepairA'> <i class='icon-ok'></i></a>" 
						+ "</td>";
				strhtml += "</tr>";
				$("tbody").append(strhtml);
			});
		});
	});
	function showPage(page) {
		$.ajax({
				type : "POST",
				url : "repair!search.action",
				data : {
					curPage : page,
					searchname : $("#searchname").val(),
					datemin: $("#datemin").val(),
					datemax: $("#datemax").val(),
					flag: "等待处理"
				},
				success : function(data, status) {
					var json = JSON.parse(data);
					if (json.page.currentPage != 1) {
						$("#first").show();
					} else {
						$("#first").hide();
						$("#next").attr("href",
								"javascript:showPage(2)");
						$("#last").show();
					}
					if (json.page.hasPrePage) {
						$("#prev").show();
						$("#prev").attr(
								"href",
								"javascript:showPage("
										+ (json.page.currentPage - 1)
										+ ")");
					} else {
						$("#prev").hide();
					}
					if (json.page.hasNextPage) {
						$("#next").show();
						$("#next").attr(
								"href",
								"javascript:showPage("
										+ (json.page.currentPage + 1)
										+ ")");
					} else {
						$("#next").hide();
						$("#last").hide();
					}
					if (json.page.currentPage < json.page.totalPage) {
						$("#last").show();
					} else {
						$("#last").hide();
					}
					$("#current").html("第" + json.page.currentPage + "页");
					$("#total").html("共" + json.page.totalPage + "页");
					$("tbody").empty();
					console.log(json.list);
					$.each(json.list,function(n, obj) {
						var strhtml = "<tr class='text-c'>";
						strhtml += "<td><input type='checkbox' name='chk_id' value='" + obj.repair_id + "' /></td>";
						strhtml += "<td>" + obj.repair_id
								+ "</td>";
						strhtml += "<td><u style='cursor: pointer' class='text-primary'"
								+ " onclick='user_show('10001','400','','" + obj.user_name + "','user!show.action?user_id=" + obj.user_id + "')'>"
								+ obj.user_name + "</u></td>"
						strhtml += "<td>"
								+ (obj.repair_content==null?'':obj.repair_content)
								+ "</td>";
						strhtml += "<td>"
								+ (obj.repair_addr==null?'':obj.repair_addr)
								+ "</td>";
						strhtml += "<td>"
								+ (obj.repair_state==null?'':obj.repair_state)
								+ "</td>";
						strhtml += "<td>"
								+ (obj.repair_submit_time==null?'':obj.repair_submit_time)
								+ "</td>";
						strhtml += "<td>"
								+ (obj.repair_person_name==null?'':obj.repair_person_name)
								+ "</td>";
						strhtml += "<td><a title='删除' class='ml-5' name='deleteBtn'" 
								+ "style='text-decoration: none'> <i class='icon-trash'></i></a></td>"
						strhtml += "<td class='f-14 user-manage'>"
								+ "<a title='等待维修' href='repair!waitingRepair.action?repair_id=" + obj.repair_id + "' class='ml-5'"
								+ "style='text-decoration: none' name='waitingRepairA'> <i class='icon-edit'></i></a><span>&nbsp;&nbsp;</span>"
								+ "<a title='正在处理' href='repair!repairing.action?repair_id=" + obj.repair_id + "' class='ml-5'"
								+ "style='text-decoration: none' name='repairingA'> <i class='icon-print'></i></a><span>&nbsp;&nbsp;</span>"
								+ "<a title='维修成功' href='repair!successRepair.action?repair_id=" + obj.repair_id + "' class='ml-5'"
								+ "style='text-decoration: none' name='successRepairA'> <i class='icon-ok'></i></a>" 
								+ "</td>";
						strhtml += "</tr>";
						$("tbody").append(strhtml);
					});
				}
			});
	}
	</script>

	<div class="navul">
		<input type="hidden" id="maxPage" value="${page.totalPage }" />
		<ul>
			<li><a id="first" style="display: none;"
				class="btn btn-danger radius" href="javascript:showPage(1)">首页</a> <c:if
					test="${page.currentPage!=1 }">
					<a id="first" class="btn btn-danger radius"
						href="javascript:showPage(1)">首页</a>
				</c:if></li>
			<li><a id="prev" style="display: none;"
				class="btn btn-danger radius"
				href="javascript:showPage(${page.currentPage-1 })">上一页</a> <c:if
					test="${page.hasPrePage }">
					<a id="prev" class="btn btn-danger radius"
						href="javascript:showPage(${page.currentPage-1 })">上一页</a>
				</c:if></li>
			<li><c:if test="${page.hasNextPage }">
					<a id="next" class="btn btn-danger radius"
						href="javascript:showPage(${page.currentPage+1 })">下一页</a>
				</c:if></li>
			<li><c:if test="${page.currentPage < page.totalPage }">
					<a id="last" class="btn btn-danger radius"
						href="javascript:showPage(${page.totalPage })">最后一页</a>
				</c:if></li>
			<li><span class="btn btn-default disabled" id="current">第${page.currentPage }
					页</span></li>
			<li><span class="btn btn-default disabled" id="total">共
					${page.totalPage } 页</span></li>
		</ul> 
	</div>
	
	<script type="text/javascript" src="admin/Hui/lib/jquery.min.js"></script>
	<script type="text/javascript"
		src="admin/Hui/lib/layer1.8/layer.min.js"></script>
	<script type="text/javascript" src="admin/Hui/lib/laypage/laypage.js"></script>
	<script type="text/javascript"
		src="admin/Hui/lib/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript"
		src="admin/Hui/lib/jquery.dataTables.min.js"></script>
	<script type="text/javascript" src="admin/Hui/js/H-ui.js"></script>
	<script type="text/javascript" src="admin/Hui/js/H-ui.admin.js"></script>
	<script type="text/javascript" src="admin/Hui/js/H-ui.admin.doc.js"></script>
		<script>
		$(function() {
			$("[name='acceptRepairA']").on("click", function() {
				var hrefUrl = $(this).attr("href");
				var thisA = $(this);
				$.post(hrefUrl, null , function(data, status) {
					if (data == 1) {
						alert("该报障状态已改为“正在处理”，请在“正在处理”菜单中查看");
						thisA.html(" <i class='xuanzhong'>&#xf00b2;</i>") ;
						var parent = thisA.parent().parent();
						parent.remove();
						var stateTotalCount = parseInt($("#stateTotalCount").html());
						stateTotalCount --;
						$("#stateTotalCount").html(stateTotalCount)
					}else
					{
						alert('该报障已经被受理，请在“正在处理”菜单中查看');
						parent.remove();
					}
				});
				return false;
			});
		});
	</script>
	
	<script type="text/javascript">
		$('.table-sort').dataTable({
			"lengthMenu" : false,//显示数量选择 
			"bFilter" : false,//过滤功能
			"bPaginate" : false,//翻页信息
			"bInfo" : false,//数量信息
			"aaSorting" : [ [ 1, "desc" ] ],//默认第几个排序
			"bStateSave" : true,//状态保存
			"aoColumnDefs" : [
			//{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
			{
				"orderable" : false,
				"aTargets" : [ 0, 2, 3, 4, 5, 6, 7, 9,10]
			} // 制定列不参与排序
			]
		});

	</script>
	<script>
		var _hmt = _hmt || [];
		(function() {
			var hm = document.createElement("script");
			hm.src = "//hm.baidu.com/hm.js?080836300300be57b7f34f4b3e97d911";
			var s = document.getElementsByTagName("script")[0];
			s.parentNode.insertBefore(hm, s);
		})();
		var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://"
				: " http://");
		document
				.write(unescape("%3Cscript src='"
						+ _bdhmProtocol
						+ "hm.baidu.com/h.js%3F080836300300be57b7f34f4b3e97d911' type='text/javascript'%3E%3C/script%3E"));
	</script>
</body>
</html>